package work.xiaohong.saolei.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.saolei.dao.SaoleiGradeMapper;
import work.xiaohong.saolei.pojo.Grade;
import work.xiaohong.saolei.service.SaoleiGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SaoleiGradeServiceImpl implements SaoleiGradeService {

    @Autowired
    private SaoleiGradeMapper saoleiGradeMapper;


    /**
     * 条件+分页查询SaoleiGrade
     * @param grade 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Grade> findPage(Grade grade, int page, int size){
        // 构建查询条件
        QueryWrapper<Grade> queryWrapper = new QueryWrapper<Grade>(grade);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return saoleiGradeMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询SaoleiGrade
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Grade> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return saoleiGradeMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法SaoleiGrade
     * @param grade
     * @return
     */
    @Override
    public List<Grade> findList(Grade grade){
        // 构建查询条件
        QueryWrapper<Grade> queryWrapper = new QueryWrapper<Grade>(grade);
        // 查询数据
        return saoleiGradeMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除SaoleiGrade
     * @param id
     */
    @Override
    public void delete(Long id){
        saoleiGradeMapper.deleteById(id);
    }

    /**
     * 根据ID修改SaoleiGrade
     * @param grade
     */
    @Override
    public void update(Grade grade){
        // 初始化一些不可修改数据
        grade.setGmtModified(null);
        grade.setGmtCreate(null);
        grade.setVersion(null);
        grade.setDeleted(null);
        saoleiGradeMapper.updateById(grade);
    }

    /**
     * 增加SaoleiGrade
     * @param grade
     */
    @Override
    public void add(Grade grade){
        saoleiGradeMapper.insert(grade);
    }

    /**
     * 根据ID查询SaoleiGrade
     * @param id
     * @return
     */
    @Override
    public Grade findById(Long id){
        return  saoleiGradeMapper.selectById(id);
    }

    /**
     * 查询全部SaoleiGrade数据
     * @return
     */
    @Override
    public List<Grade> findAll() {
        return saoleiGradeMapper.selectList(null);
    }
}
